<?php

namespace App\Library\Service;

use Illuminate\Http\JsonResponse;
use Yansongda\Pay\Pay;

class DouyinService extends BaseService
{
    /**
     * mini
     * @param string $serialNumber
     * @param float $price
     * @return JsonResponse
     */
    public function mini(string $serialNumber, float $price): JsonResponse
    {
        $result = Pay::douyin()->mini([
            'out_order_no' => $serialNumber,
            'total_amount' => prod() ? (int)bcmul($price, 100) : 1,
            'subject' => $serialNumber,
            'body' => $serialNumber,
            'valid_time' => 600,
        ]);
        if (!empty($result->code)) return failMessage($result->message);
        return success($result);
    }
}
